package com.example.osixaffairssystem.service.impl;

import com.example.osixaffairssystem.domain.PageBean;
import com.example.osixaffairssystem.domain.model.Class;
import com.example.osixaffairssystem.mapper.ClassMapper;
import com.example.osixaffairssystem.service.ClassService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@RequiredArgsConstructor
public class ClassServiceImpl implements ClassService {

    final ClassMapper classMapper;

    @Override
    public List<Class> list() {
        return classMapper.list();
    }

    @Override
    public PageBean<Class> listToPage(Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        Page<Class> p = (Page<Class>) classMapper.list();
        return new PageBean<>(p.getTotal(), p.getResult());
    }


    @Override
    public Integer insert(Class clazz) {
        classMapper.insert(clazz);
        return clazz.getId();
    }

    @Override
    public void update(Class clazz) {
        classMapper.update(clazz);
    }

    @Override
    public void delete(List<Integer> ids) {
        classMapper.delete(ids);
    }
}
